package com.example.tys.dex;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    public MyService.MyBinder binder;
    private ServiceConnection con = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            binder = (MyService.MyBinder) service;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            unbindService(con);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String a = getString(R.string.app_name);
        Log.i("-----", "activity:" + getApplication());
        Log.i("-----", "activity:" + getApplicationContext());
        Log.i("-----", "activity:" + getApplicationInfo().className +" : "+a+" 包名:" +getPackageName());

        Intent server = new Intent(this, MyService.class);
        startService(server);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Toast.makeText(getApplication(), getApplication().getApplicationInfo().packageName, Toast.LENGTH_SHORT).show();
    }

    public void tv(View view) {
        Intent intent = new Intent("com.dongnao.broadcast.test");
        intent.setComponent(new ComponentName(getPackageName(), MyReceiver.class.getName()));
        sendBroadcast(intent);

        getContentResolver().delete(Uri.parse("content://com.example.tys.dex/test"), null,
                null);
    }
}
